package com.goldenKey.admin.controller;

import com.goldenKey.common.pojo.result.R;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.goldenKey.common.pojo.po.Admin;
import com.goldenKey.admin.service.IAdminService;

/**
 * @Author: 吃我一钊
 * @Description: 控制层
 * @Date: 2025/02/02
 */
@RestController
@RequestMapping("/admin")
public class AdminController {

	@Autowired
	private IAdminService adminService;

	/**
	 * 新增数据
	 * @param admin
	 * @return
	 */
	@PostMapping("/save")
	public R<Void> save(@RequestBody Admin admin) {
		adminService.save(admin);
		return R.ok();
	}

	/**
	 * 根据id删除
	 * @param adminId
	 * @return
	 */
	@DeleteMapping("/deleteById/{adminId}")
	public R<Void> deleteById(@PathVariable("adminId") Integer adminId) {
		adminService.removeById(adminId);
		return R.ok();
	}

	/**
	 * 根据id修改数据
	 * @param admin
	 * @return
	 */
	@PutMapping("/updateById")
	public R<Void> updateById(@RequestBody Admin admin) {
		adminService.updateById(admin);
		return R.ok();
	}

	/**
	 * 根据id查询数据
	 * @param adminId
	 * @return
	 */
	@GetMapping("/getById/{adminId}")
	public R<Admin> getById(@PathVariable("adminId") Integer adminId) {
		Admin admin = adminService.getById(adminId);
		return R.ok(admin);
	}
	/**
	 * 查询所有数据
	 * @return
	 */
	@GetMapping("/list")
	public R<List<Admin>> list() {
		List<Admin> adminList = adminService.list();
		return R.ok(adminList);
	}

}